﻿namespace OpcDaNetClient
{
    public partial class Form_ServerInfo : Form
    {
        public Form_ServerInfo()
        {
            InitializeComponent();
        }
        #region " Declaration "

        private OpcDaNet.Da.Server m_OpcServer;

        #endregion

        #region " Properties "

        // hand over the server 
        public OpcDaNet.Da.Server OPCServer
        {
            set { this.m_OpcServer = value; }
        }

        #endregion

        // Step: 21
        //
        // read opc server information
        #region " Form events "

        // Step: 21
        //
        // read opc server information
        private void Form_ServerInfo_Load(object sender, EventArgs e)
        {
            try
            {
                // check precondition
                Debug.Assert(this.m_OpcServer != null);
                if (this.m_OpcServer == null)
                    return;

                // Step: 21
                //
                // read opc server information
                this.Label_Name.Text = m_OpcServer.Name;
                this.Label_URL.Text = m_OpcServer.Url.Path;
                this.Label_Status.Text = m_OpcServer.GetStatus().StatusInfo;
                this.Label_Vendor.Text = m_OpcServer.GetStatus().VendorInfo;
            }
            catch (Exception except)
            {
                this.ShowExceptionInfo(except);
            }
        }

        private void Button_OK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #endregion

        //
        #region " auxiliary functions "

        private void ShowExceptionInfo(Exception except)
        {
            StringBuilder sbText, sbCaption;
            sbText = new StringBuilder(except.Message);
            sbCaption = new StringBuilder("Exception caugth in ");
            sbCaption.Append(this.Text);
            MessageBox.Show(sbText.ToString(), sbCaption.ToString(),
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        #endregion
    }
}
